﻿using Qy.Models;
using Qy.Service;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.Extensions.DependencyInjection;
using System.Threading.Tasks;

namespace Qy.Web.Home
{
    public class Base : Controller
    {
        public Base() { }

        public override async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)
        {
            SytemConfig siteConfig = await SiteConfigAsync(context);
            ViewBag.SiteConfig = siteConfig;
            await base.OnActionExecutionAsync(context, next);
        }


        public async Task<SytemConfig> SiteConfigAsync(ActionExecutingContext context)
        {
            ConfigService _configService = context.HttpContext.RequestServices.GetService<ConfigService>();
            SytemConfig config = await _configService.GetSytemConfigAsync();
            return config;
        }
    }
}
